package com.hh.flow.service.impl;

import com.hh.flow.domain.FlowNode;
import com.hh.flow.mapper.FlowNodeMapper;
import com.hh.flow.service.IFlowNodeService;
import com.hh.mybatis.service.impl.BaseServiceImpl;
import com.mybatisflex.core.query.QueryWrapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.validation.constraints.NotBlank;
import java.util.List;

import static com.hh.flow.domain.tables.FlowNodeTableDef.flow_node;

/**
 * 流程结点Service业务层处理
 *
 * @author hh
 * @date 2023-03-29
 */
@Service
public class FlowNodeServiceImpl extends BaseServiceImpl<FlowNode> implements IFlowNodeService {
    @Resource
    private FlowNodeMapper nodeMapper;

    @Override
    public FlowNodeMapper getBaseMapper() {
        return nodeMapper;
    }

    @Override
    public QueryWrapper buildWrapper(FlowNode flowNode) {
        QueryWrapper query = QueryWrapper.create()
                .where(flow_node.node_type.eq(flowNode.getNodeType()))
                .and(flow_node.definition_id.eq(flowNode.getDefinitionId()))
                .and(flow_node.node_name.like(flowNode.getNodeName()))
                .and(flow_node.node_code.eq(flowNode.getNodeCode()))
                .and(flow_node.role_code.eq(flowNode.getRoleCode()))
                .and(flow_node.role_name.like(flowNode.getNodeName()))
                .and(flow_node.version.eq(flowNode.getVersion()));
        return query;
    }

    @Override
    public List<FlowNode> queryNewVersionFlowNodeByFlowCode(@NotBlank String flowCode) {
        return nodeMapper.queryNewVersionFlowNodeByFlowCode(flowCode);
    }

}
